#include "m_exchangemanage.h"
#include "ui_m_exchangemanage.h"

M_exchangeManage::M_exchangeManage(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::M_exchangeManage)
{
    ui->setupUi(this);
    tablequery();
}

M_exchangeManage::~M_exchangeManage()
{
    delete ui;
}

void M_exchangeManage::tablequery(){
    QString str=QString("select * from exchangroom");
    model.setQuery(str);
    ui->tableView->setModel(&model);
    ui->tableView->setColumnHidden(1,true);
    model.setHeaderData(0,Qt::Horizontal,"学号");
    model.setHeaderData(2,Qt::Horizontal,"现居住宿舍号");
    model.setHeaderData(3,Qt::Horizontal,"先居住楼栋");
    model.setHeaderData(4,Qt::Horizontal,"目标宿舍号");
    model.setHeaderData(5,Qt::Horizontal,"目标楼栋");
    model.setHeaderData(6,Qt::Horizontal,"原因");
    model.setHeaderData(7,Qt::Horizontal,"交换结果");
    model.setHeaderData(8,Qt::Horizontal,"是否同意");
    model.setHeaderData(9,Qt::Horizontal,"日期");
    model.setHeaderData(10,Qt::Horizontal,"学生姓名");
}

void M_exchangeManage::on_acceptBtn_clicked()
{
    int row = ui-> tableView ->currentIndex().row();
    QString id=model.data(model.index(row,0)).toString();

    QSqlQuery query;
    QString str=QString("update exchangroom set eflag='1',eresult='Yes' where stu_sid='%1'").arg(id);
    //qDebug()<<str;
    if(query.exec(str)){
        QMessageBox::information(NULL,"tips","同意成功");
        tablequery();
    }
    else {
        QMessageBox::warning(NULL,"Error","同意失败");
    }
}


void M_exchangeManage::on_rejectBtn_clicked()
{
    int row = ui-> tableView ->currentIndex().row();
    QString id=model.data(model.index(row,0)).toString();

    QSqlQuery query;
    QString str=QString("update exchangroom set eflag='1',eresult='No' where stu_sid='%1'").arg(id);
    if(query.exec(str)){
        QMessageBox::information(NULL,"tips","拒绝成功");
        tablequery();
    }
    else {
        QMessageBox::warning(NULL,"Error","拒绝失败");
    }
}

